package dpatterns.observer.weatherorama.observers.impl;

import java.util.Observable;
import java.util.Observer;

import dpatterns.observer.weatherorama.observers.DisplayElement;
import dpatterns.observer.weatherorama.subjects.impl.WeatherData;

public class CurrentConditions implements Observer, DisplayElement {
	private Observable observable;
	private float humidity; 
	private float temperature;
	private float pressure;
	
	public CurrentConditions(Observable observable) {
		this.observable = observable;
		observable.addObserver(this);
	}
	
	public void display() {
		System.out.println("Current weather: "+temperature+" F degrees and "+humidity+" % humidity and "+pressure+" P pressure.");
	}

	@Override
	public void update(Observable obs, Object arg) {
		if(obs instanceof WeatherData) {
			WeatherData weatherData = (WeatherData) obs;
			this.humidity = weatherData.getHumidity(); 
			this.temperature = weatherData.getTemperature();
			this.pressure = weatherData.getPressure();
		}
	}
}